/**
 * OpenAI Function Call Types
 * These types define the structure for OpenAI function calls and tools
 * Compatible with OpenAI SDK types
 */

export interface OpenAIFunction {
  name: string;
  description: string;
  parameters: Record<string, unknown>;
  strict?: boolean;
}

export interface OpenAITool {
  type: "function";
  function: OpenAIFunction;
}

export type OpenAITools = OpenAITool[];

/**
 * Tool Call Types for function calling
 */
export interface OpenAIToolCall {
  id: string;
  type: "function";
  function: {
    name: string;
    arguments: string; // JSON string
  };
}

/**
 * Tool Call Execution Status
 */
export type ToolCallStatus =
  | "pending"
  | "awaiting_approval"
  | "success"
  | "error";

/**
 * Tool Call Result for database storage
 */
export interface ToolCallResult {
  id: string;
  name: string;
  arguments: string; // JSON string of the arguments
  status: ToolCallStatus;
  result?: string; // Success result
  error?: string; // Error message
  mcpServerId?: string; // Which MCP server executed this tool
  executionTime?: number; // Execution time in milliseconds
  requiresApproval?: boolean; // Whether this tool call requires user approval
  userMessage?: string; // User-provided message (e.g., rejection reason)
}

/**
 * Tool Call Message for OpenAI API
 */
export interface ToolCallMessage {
  role: "assistant";
  content: string | null;
  tool_calls: OpenAIToolCall[];
}

/**
 * Tool Result Message for OpenAI API
 */
export interface ToolResultMessage {
  role: "tool";
  tool_call_id: string;
  content: string;
}
